import 'dart:core';

import 'package:flutter/material.dart';
import 'package:untitled/pages/home/tab_index/index.dart';
import 'package:untitled/pages/home/tab_info/index.dart';
import 'package:untitled/pages/home/tab_mine/index.dart';
import 'package:untitled/pages/home/tab_search/index.dart';
import 'package:untitled/widgets/page_content.dart';

//1需要准备4个tab内容区域
List<Widget> tabViewList=[
  TabIndex(),
  TabSearch(),
  TabInfo(),
  TabHome(),
];
//2需要4个BottomNavigationBarItem
List<BottomNavigationBarItem> barItemList=[
  BottomNavigationBarItem(icon: Icon(Icons.home),label: '首页'),
  BottomNavigationBarItem(icon: Icon(Icons.search),label: '找房'),
  BottomNavigationBarItem(icon: Icon(Icons.info),label: '资讯'),
  BottomNavigationBarItem(icon: Icon(Icons.account_circle),label: '我的'),
];
class HomePage extends StatefulWidget {
  const HomePage({Key key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  int _selectedIndex = 0;
  void _onItemTapped(int index){
    setState(() {
      _selectedIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
     body: tabViewList[_selectedIndex],
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,//tab多于4个用这个属性
        items: barItemList,
        currentIndex: _selectedIndex,
        selectedItemColor: Colors.green,
        onTap: _onItemTapped
      ),
    );
  }
}

